#include "GumdropSkeleton.h"

const GLfloat RADIUS = 0.1f;
const GLint SLICES = 5;
const GLint STACKS = 5;
const GLfloat PI = 3.14159;
const GLfloat CONEWATERLEVEL = 10;
enum animations {IDLE, WALKING};
GLint currentAnimation = IDLE; 

//GumdropSkeleton Initialize methods
void GumdropSkeleton::LoadGumdropSkeleton()
{
	LoadWater();
	LoadSpine();
	LoadShoulders();
	LoadLeftArm();
	LoadRightArm();
	LoadPelvis();
	LoadLeftLeg();
	LoadRightLeg();
}
void GumdropSkeleton::LoadWater()
{
	coneWaterLevel = 10.0f-0.01f;
	baseRadius = 3.0f-0.01f;
	topRadius = 0.0f;
	height = 10.0f-0.01f;
	sphereRadius = 35*RADIUS-0.01f;
}
void GumdropSkeleton::LoadSpine()
{
	//neck starting position
	spine[0][0] = 0.0f;
	spine[0][1] = 0.0f;
	spine[0][2] = 0.0f;

	// shoulder joint starting position
	spine[1][0] = -1.0f;
	spine[1][1] = -2.0f;
	spine[1][2] = 0.0f;

	// Abdomin ending position
	spine[2][0] = -2.0f;
	spine[2][1] = -10.0f;
	spine[2][2] = 0.0f;
}
void GumdropSkeleton::LoadShoulders()
{
	//Left Arm joint
	shoulders[0][0] = -2.0f;
	shoulders[0][1] = -0.5f;
	shoulders[0][2] = 0.0f;

	//Spinal Joint
	shoulders[1][0] = 0.0f;
	shoulders[1][1] = 0.0f;
	shoulders[1][2] = 0.0f;

	//Right Arm Joint
	shoulders[2][0] = 2.0f;
	shoulders[2][1] = -0.5f;
	shoulders[2][2] = 0.0f;
}
void GumdropSkeleton::LoadLeftArm()
{
	//Shoulder joint
	leftArm[0][0] = 0.0f;
	leftArm[0][1] = 0.0f;
	leftArm[0][2] = 0.0f;

	//elbow joint
	leftArm[1][0] = -1.0f;
	leftArm[1][1] = -2.0f;
	leftArm[1][2] = 0.0f;

	//left hand
	leftArm[2][0] = 0.0f;
	leftArm[2][1] = -3.0f;
	leftArm[2][2] = 0.0f;

}
void GumdropSkeleton::LoadRightArm()
{
	//Shoulder joint
	rightArm[0][0] = 0.0f;
	rightArm[0][1] = 0.0f;
	rightArm[0][2] = 0.0f;

	//elbow joint
	rightArm[1][0] = -1.0f;
	rightArm[1][1] = -2.0f;
	rightArm[1][2] = 0.0f;

	//right hand
	rightArm[2][0] = 0.0f;
	rightArm[2][1] = -3.0f;
	rightArm[2][2] = 0.0f;
}
void GumdropSkeleton::LoadPelvis()
{
	//left leg joint
	pelvis[0][0] = 0.0f;
	pelvis[0][1] = 0.0f;
	pelvis[0][2] = 0.0f;

	//Spinal joint
	pelvis[1][0] = 3.0f;
	pelvis[1][1] = 1.0f;
	pelvis[1][2] = 0.0f;

	//right Leg joint
	pelvis[2][0] = 6.0f;
	pelvis[2][1] = 0.0f;
	pelvis[2][2] = 0.0f;

}
void GumdropSkeleton::LoadLeftLeg()
{
	//Load Pelvis joint
	leftLeg[0][0] = 0.0f;
	leftLeg[0][1] = 0.0f;
	leftLeg[0][2] = 0.0f;

	//Load Foot
	leftLeg[1][0] = -1.0f;
	leftLeg[1][1] = -3.0f;
	leftLeg[1][2] = 0.0f;

}
void GumdropSkeleton::LoadRightLeg()
{
	//Load Pelvis Joint
	rightLeg[0][0] = 0.0f;
	rightLeg[0][1] = 0.0f;
	rightLeg[0][2] = 0.0f;

	//Load Foot
	rightLeg[1][0] = 1.0f;
	rightLeg[1][1] = -3.0f;
	rightLeg[1][2] = 0.0f;
}

//GumdropSkeleton Update methtods
/*void GumdropSkeleton::UpdateGumdropSkeleton(){}
void GumdropSkeleton::UpdateSpine(){}
void GumdropSkeleton::UpdateShoulders(){}
void GumdropSkeleton::UpdateLeftArm(){}
void GumdropSkeleton::UpdateRightArm(){}
void GumdropSkeleton::UpdatePelvis(){}
void GumdropSkeleton::UpdateLeftLeg(){}
void GumdropSkeleton::UpdateRightLeg(){}
*/
//GumdropSkeleton Draw Methods
void GumdropSkeleton::DrawGumdropSkeleton()
{
	glColor3f(1.0f, 0.0f, 1.0f);
	glPushMatrix();
		glTranslatef(2.0f, 14.0f, 0.0f);
		glColor3f(0.0f, 0.0f, 1.0f);
		DrawWater();
		glColor3f(1.0f, 0.0f, 1.0f);
		DrawSpine();
	glPopMatrix();

	glPushMatrix();
		glTranslatef(1.0f, 12.0f, 0.0f);
		glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
		DrawShoulders();
	glPopMatrix();

	glPushMatrix();
		glTranslatef(1.0f, 11.5f, 2.0f);
		DrawLeftArm();
	glPopMatrix();
	

	glPushMatrix();
		glTranslatef(1.0f, 11.5f, -2.0f);
		DrawRightArm();
	glPopMatrix();
	

	glPushMatrix();
		glTranslatef(0.0f, 3.0, 3.0f);
		glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
		DrawPelvis();
	glPopMatrix();
	
	glPushMatrix();
		glTranslatef(0.0f, 3.0f, 3.0f);
		glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
		DrawLeftLeg();
	glPopMatrix();

	glPushMatrix();
		glTranslatef(0.0f, 3.0f, -3.0f);
		glRotatef(90.0, 0.0f, 1.0f, 0.0f); 
		DrawRightLeg();
	glPopMatrix(); 


}

void GumdropSkeleton::drawCylinder(GLfloat baseRadius, GLfloat topRadius, GLfloat height)
{

	// Glut provides functions for cube and sphere, but not for cylinder, cone.
	// Hence this glu function has to be called.

	GLUquadricObj* cyl = NULL;
	cyl = gluNewQuadric();
	gluQuadricDrawStyle(cyl, GLU_LINE);

	GLfloat stacks = coneWaterLevel * STACKS * STACKS*2 / CONEWATERLEVEL;

	glPushMatrix();

		gluCylinder(cyl, baseRadius, topRadius, height, SLICES * SLICES, stacks);
		gluDeleteQuadric(cyl);

	glPopMatrix();
}

void GumdropSkeleton::DrawWater()
{
	glPushMatrix();
		glTranslatef(spine[2][0], spine[2][1], spine[2][2]);
		glutWireSphere(sphereRadius, SLICES*SLICES, STACKS * STACKS);
		glTranslatef(0.0f, 2.0f, 0.0f);
		glRotatef(90.0f, -1.0f, 0.0f, -0.1f);
		height = coneWaterLevel;
		//glutWireCone(3.0f, 10.0f, SLICES*SLICES, STACKS*STACKS);
		drawCylinder(baseRadius, topRadius, height);
	glPopMatrix();
}

void GumdropSkeleton::DrawSpine()
{
	glBegin(GL_LINES);
		glVertex3f(spine[0][0], spine[0][1], spine[0][2]);
		glVertex3f(spine[1][0], spine[1][1], spine[1][2]);
		glVertex3f(spine[1][0], spine[1][1], spine[1][2]);
		glVertex3f(spine[2][0], spine[2][1], spine[2][2]);
	glEnd();

	glPushMatrix();
		glTranslatef(spine[2][0], spine[2][1], spine[2][2]);
		glutWireSphere(35*RADIUS, SLICES*SLICES, STACKS * STACKS);
		glTranslatef(0.0f, 2.0f, 0.0f);
		glRotatef(90.0f, -1.0f, 0.0f, -0.1f);
		glutWireCone(3.0f, 10.0f, SLICES*SLICES, STACKS*STACKS);
	glPopMatrix();
	
	glPushMatrix();
		glTranslatef(spine[1][0], spine[1][1], spine[1][2]);
		glutWireSphere(RADIUS, SLICES, STACKS);
	glPopMatrix();

	glPushMatrix();
		glTranslatef(spine[2][0], spine[2][1], spine[2][2]);
		glutWireSphere(RADIUS, SLICES, STACKS);
	glPopMatrix();


}
void GumdropSkeleton::DrawShoulders()
{
	glBegin(GL_LINES);
		glVertex3f(shoulders[0][0], shoulders[0][1], shoulders[0][2]);
		glVertex3f(shoulders[1][0], shoulders[1][1], shoulders[1][2]);
		glVertex3f(shoulders[1][0], shoulders[1][1], shoulders[1][2]);
		glVertex3f(shoulders[2][0], shoulders[2][1], shoulders[2][2]);
	glEnd();

	glPushMatrix();
		glTranslatef(shoulders[1][0], shoulders[1][1], shoulders[1][2]);
		glPushMatrix();
			glRotatef(90.0f, 0.0f, 1.0f, -0.2f);
			glutWireCone(0.1, 2.0, 2*SLICES, 2*STACKS);
		glPopMatrix();
		glPushMatrix();
			glRotatef(-90.0f, 0.0f, 1.0f, -0.2f);
			glutWireCone(0.1, 2.0, 2*SLICES, 2*STACKS);
		glPopMatrix();

	glPopMatrix();
	glPushMatrix();
		glTranslatef(shoulders[0][0], shoulders[0][1], shoulders[0][2]);
		glutWireSphere(RADIUS, SLICES, STACKS);
		glRotatef(120.0f, 1.0f, 0.0f, 0.0f);
		glutWireCone(0.1, 2.0, 2*SLICES, 2*STACKS);
	glPopMatrix();

	glPushMatrix();
		glTranslatef(shoulders[2][0], shoulders[2][1], shoulders[2][2]);
		glutWireSphere(RADIUS, SLICES, STACKS);
		glRotatef(120.0f, 1.0f, 0.0f, 0.0f);
		glutWireCone(0.1, 2.0, 2*SLICES, 2*STACKS);
	glPopMatrix();
}
void GumdropSkeleton::DrawLeftArm()
{
	glBegin(GL_LINES);
		glVertex3f(leftArm[0][0], leftArm[0][1], leftArm[0][2]);
		glVertex3f(leftArm[1][0], leftArm[1][1], leftArm[1][2]);
		glVertex3f(leftArm[1][0], leftArm[1][1], leftArm[1][2]);
		glVertex3f(leftArm[2][0], leftArm[2][1], leftArm[2][2]);
	glEnd();

	glPushMatrix();
		glTranslatef(leftArm[1][0], leftArm[1][1], leftArm[1][2]);
		glutWireSphere(RADIUS, SLICES, STACKS);
		glRotatef(-140.0f, 0.0f, -1.0f, 1.0f);
		glutWireCone(0.1, 2.0, 2*SLICES, 2*STACKS);
	glPopMatrix();
}
void GumdropSkeleton::DrawRightArm()
{
	glBegin(GL_LINES);
		glVertex3f(rightArm[0][0], rightArm[0][1], rightArm[0][2]);
		glVertex3f(rightArm[1][0], rightArm[1][1], rightArm[1][2]);
		glVertex3f(rightArm[1][0], rightArm[1][1], rightArm[1][2]);
		glVertex3f(rightArm[2][0], rightArm[2][1], rightArm[2][2]);
	glEnd();

	glPushMatrix();
		glTranslatef(rightArm[1][0], rightArm[1][1], rightArm[1][2]);
		glutWireSphere(RADIUS, SLICES, STACKS);
		glRotatef(-140.0f, 0.0f, -1.0f, 1.0f);
		glutWireCone(0.1, 2.0, 2*SLICES, 2*STACKS);
	glPopMatrix();
}
void GumdropSkeleton::DrawPelvis()
{
	glBegin(GL_LINES);
		glVertex3f(pelvis[0][0], pelvis[0][1], pelvis[0][2]);
		glVertex3f(pelvis[1][0], pelvis[1][1], pelvis[1][2]);
		glVertex3f(pelvis[1][0], pelvis[1][1], pelvis[1][2]);
		glVertex3f(pelvis[2][0], pelvis[2][1], pelvis[2][2]);
	glEnd();

	glPushMatrix();
		glTranslatef(pelvis[0][0], pelvis[0][1], pelvis[0][2]);
		glutWireSphere(RADIUS, SLICES, STACKS);
		glRotatef(90.0f, 1.0f, 0.0f, -0.4f);
		glutWireCone(0.4, 3.0, 2*SLICES, 2*STACKS);
	glPopMatrix();

	glPushMatrix();
		glTranslatef(pelvis[2][0], pelvis[2][1], pelvis[2][2]);
		glutWireSphere(RADIUS, SLICES, STACKS);
		glRotatef(90.0f, 1.0f, 0.0f, 0.4f);
		glutWireCone(0.4, 3.0, 2*SLICES, 2*STACKS);
	glPopMatrix();


}
void GumdropSkeleton::DrawLeftLeg()
{
	glBegin(GL_LINES);
		glVertex3f(leftLeg[0][0], leftLeg[0][1], leftLeg[0][2]);
		glVertex3f(leftLeg[1][0], leftLeg[1][1], leftLeg[1][2]);
	glEnd();
}
void GumdropSkeleton::DrawRightLeg()
{
	glBegin(GL_LINES);
		glVertex3f(rightLeg[0][0], rightLeg[0][1], rightLeg[0][2]);
		glVertex3f(rightLeg[1][0], rightLeg[1][1], rightLeg[1][2]);
	glEnd();
}

void GumdropSkeleton::LiftLeftLeg(GLint milliseconds)
{
	GLfloat interval;

	//Point of rotation is the right leg joint on the pelvis
	//Rotate the model clockwise about the x-axis on point

	//if no time given, then just show the keyframe
	interval = (milliseconds == 0? 100.0f*PI/180.0f : 100.0f*PI/180.0f/(GLfloat)milliseconds);


	pelvis[0][0] += interval;
	pelvis[0][1] += interval;
	pelvis[1][0] += interval;
	pelvis[1][1] += interval;


	//Rotate all body parts the same way

	//Left leg
	//Load Pelvis joint
	leftLeg[0][0] += interval;
	leftLeg[0][1] += interval;
	//leftLeg[0][2] += interval;

	//Load Foot
	leftLeg[1][0] += interval;
	leftLeg[1][1] += interval;
	//leftLeg[1][2] += interval;

	//Spine
	//neck starting position
	//spine[0][0] += interval;
	spine[0][1] += interval;
	spine[0][2] -= interval;

	// shoulder joint starting position
	//spine[1][0] += interval;
	spine[1][1] += interval;
	spine[1][2] -= interval;

	// Abdomin ending position
	//spine[2][0] += interval;
	spine[2][1] += interval;
	spine[2][2] -= interval;
	
	//shoulders
	//Left Arm joint
	shoulders[0][0] += interval;
	shoulders[0][1] += interval;
	//shoulders[0][2] = 0.0f;

	//Spinal Joint
	shoulders[1][0] += interval;
	shoulders[1][1] += interval;
	//shoulders[1][2] = 0.0f;

	//Right Arm Joint
	shoulders[2][0] += interval;
	shoulders[2][1] += interval;

	//rightArm
	//Shoulder joint
	//rightArm[0][0] += interval;
	rightArm[0][1] += interval;
	rightArm[0][2] -= interval;

	//elbow joint
	//rightArm[1][0] += interval;
	rightArm[1][1] += interval;
	rightArm[1][2] -= interval;

	//right hand
	//rightArm[2][0] += interval;
	rightArm[2][1] += interval;
	rightArm[2][2] -= interval;

	//leftArm
	//Shoulder joint
	//leftArm[0][0] += interval;
	leftArm[0][1] += interval;
	leftArm[0][2] -= interval;

	//elbow joint
	//leftArm[1][0] += interval;
	leftArm[1][1] += interval;
	leftArm[1][2] -= interval;

	//left hand
	//leftArm[2][0] += interval;
	leftArm[2][1] += interval;
	leftArm[2][2] -= interval;


		
}
void GumdropSkeleton::MoveLeftLegForward(GLint milliseconds)
{
	GLfloat interval;

	//if no time given, then just show the keyframe
	interval = (milliseconds == 0? 100.0f*PI/180.0f :  100.0f*PI/180.0f/(GLfloat)milliseconds);

	//Rotate entire model about the y-axis with pivot pelvis right leg joint
	//pelvis[0][0] += interval;
	//pelvis[0][1] += interval;
	pelvis[0][2] += interval;//pelvis[2][2] + interval;
	//pelvis[1][2] += /*pelvis[2][2] + */interval;


	//Rotate all body parts the same way

	//Left leg
	//Load Pelvis joint
	//leftLeg[0][0] += interval;
	//leftLeg[0][1] += interval;
	leftLeg[0][2] += interval;//pelvis[2][2] + interval;

	//Load Foot
	//leftLeg[1][0] += interval;
	//leftLeg[1][1] += interval;
	leftLeg[1][2] += interval;//pelvis[2][2] + interval;

	//Spine
	//neck starting position
	//spine[0][0] += interval;
	//spine[0][1] += interval;
	//spine[0][0] += interval;//pelvis[2][2] + interval;

	// shoulder joint starting position
	//spine[1][0] += interval;
	//spine[1][1] += interval;
	//spine[1][0] += interval;//pelvis[2][2] + interval;

	// Abdomin ending position
	//spine[2][0] += interval;
	//spine[2][1] += interval;
	//spine[2][0] += interval;//pelvis[2][2] + interval;
	
	//shoulders
	//Left Arm joint
	//shoulders[0][0] += interval;
	//shoulders[0][1] += interval;
	//shoulders[0][2] += interval;//pelvis[2][2] + interval;

	//Spinal Joint
	//shoulders[1][0] += interval;
	//shoulders[1][1] += interval;
	//shoulders[1][2] += interval;//pelvis[2][2] + interval;

	//Right Arm Joint
	//shoulders[2][0] += interval;
	//shoulders[2][1] += interval;
	//shoulders[2][2] += interval;//pelvis[2][2] + interval;

	//rightArm
	//Shoulder joint
	//rightArm[0][0] += interval;
	//rightArm[0][1] += interval;
	//rightArm[0][0] += interval;//pelvis[2][2] + interval;

	//elbow joint
	//rightArm[1][0] += interval;
	//rightArm[1][1] += interval;
	//rightArm[1][0] += interval;//pelvis[2][2] + interval;

	//right hand
	//rightArm[2][0] += interval;
	//rightArm[2][1] += interval;
	//rightArm[2][0] += interval;//pelvis[2][2] + interval;

	//leftArm
	//Shoulder joint
	//leftArm[0][0] += interval;
	//leftArm[0][1] += interval;
	//leftArm[0][0] += interval; //pelvis[2][2] + interval;

	//elbow joint
	//leftArm[1][0] += interval;
	//leftArm[1][1] += interval;
	//leftArm[1][0] += interval;//pelvis[2][2] +  interval;

	//left hand
	//leftArm[2][0] += interval;
	//leftArm[2][1] += interval;
	//leftArm[2][0] += interval;//pelvis[2][2] + interval;

}
void GumdropSkeleton::DropLeftLeg(GLint milliseconds)
{
	GLfloat interval;

	//Point of rotation is the right leg joint on the pelvis
	//Rotate the model counter-clockwise about the x-axis on point
	//if no time given, then just show the keyframe
	interval = (milliseconds == 0? -100.0f*PI/180.0f : -100.0f*PI/180.0f/(GLfloat)milliseconds);


	pelvis[0][0] += interval;
	pelvis[0][1] += interval;
	pelvis[1][0] += interval;
	pelvis[1][1] += interval;


	//Left leg
	//Load Pelvis joint
	leftLeg[0][0] += interval;
	leftLeg[0][1] += interval;
	//leftLeg[0][2] += interval;

	//Load Foot
	leftLeg[1][0] += interval;
	leftLeg[1][1] += interval;
	//leftLeg[1][2] += interval;

	//Spine
	//neck starting position
	//spine[0][0] += interval;
	spine[0][1] += interval;
	spine[0][2] -= interval;

	// shoulder joint starting position
	//spine[1][0] += interval;
	spine[1][1] += interval;
	spine[1][2] -= interval;

	// Abdomin ending position
	//spine[2][0] += interval;
	spine[2][1] += interval;
	spine[2][2] -= interval;
	
	//shoulders
	//Left Arm joint
	shoulders[0][0] += interval;
	shoulders[0][1] += interval;
	//shoulders[0][2] = 0.0f;

	//Spinal Joint
	shoulders[1][0] += interval;
	shoulders[1][1] += interval;
	//shoulders[1][2] = 0.0f;

	//Right Arm Joint
	shoulders[2][0] += interval;
	shoulders[2][1] += interval;

	//rightArm
	//Shoulder joint
	//rightArm[0][0] += interval;
	rightArm[0][1] += interval;
	rightArm[0][2] -= interval;

	//elbow joint
	//rightArm[1][0] += interval;
	rightArm[1][1] += interval;
	rightArm[1][2] -= interval;

	//right hand
	//rightArm[2][0] += interval;
	rightArm[2][1] += interval;
	rightArm[2][2] -= interval;

	//leftArm
	//Shoulder joint
	//leftArm[0][0] += interval;
	leftArm[0][1] += interval;
	leftArm[0][2] -= interval;

	//elbow joint
	//leftArm[1][0] += interval;
	leftArm[1][1] += interval;
	leftArm[1][2] -= interval;

	//left hand
	//leftArm[2][0] += interval;
	leftArm[2][1] += interval;
	leftArm[2][2] -= interval;

}

void GumdropSkeleton::LiftRightLeg(GLint milliseconds)
{
		GLfloat interval;

	//Point of rotation is the right leg joint on the pelvis
	//Rotate the model counter-clockwise about the x-axis on point
	//if no time given, then just show the keyframe
	interval = (milliseconds == 0? 100.0f*PI/180.0f : 100.0f*PI/180.0f/(GLfloat)milliseconds);


	pelvis[1][0] += interval;
	pelvis[1][1] += interval;
	pelvis[2][0] += interval;
	pelvis[2][1] += interval;


	//Right leg
	//Load Pelvis joint
	rightLeg[0][0] += interval;
	rightLeg[0][1] += interval;
	//rightLeg[0][2] += interval;

	//Load Foot
	rightLeg[1][0] += interval;
	rightLeg[1][1] += interval;
	//rightLeg[1][2] += interval;

	//Spine
	//neck starting position
	//spine[0][0] += interval;
	spine[0][1] += interval;
	spine[0][2] -= interval;

	// shoulder joint starting position
	//spine[1][0] += interval;
	spine[1][1] += interval;
	spine[1][2] -= interval;

	// Abdomin ending position
	//spine[2][0] += interval;
	spine[2][1] += interval;
	spine[2][2] -= interval;
	
	//shoulders
	//Left Arm joint
	shoulders[0][0] += interval;
	shoulders[0][1] += interval;
	//shoulders[0][2] = 0.0f;

	//Spinal Joint
	shoulders[1][0] += interval;
	shoulders[1][1] += interval;
	//shoulders[1][2] = 0.0f;

	//Right Arm Joint
	shoulders[2][0] += interval;
	shoulders[2][1] += interval;

	//rightArm
	//Shoulder joint
	//rightArm[0][0] += interval;
	rightArm[0][1] += interval;
	rightArm[0][2] -= interval;

	//elbow joint
	//rightArm[1][0] += interval;
	rightArm[1][1] += interval;
	rightArm[1][2] -= interval;

	//right hand
	//rightArm[2][0] += interval;
	rightArm[2][1] += interval;
	rightArm[2][2] -= interval;

	//leftArm
	//Shoulder joint
	//leftArm[0][0] += interval;
	leftArm[0][1] += interval;
	leftArm[0][2] -= interval;

	//elbow joint
	//leftArm[1][0] += interval;
	leftArm[1][1] += interval;
	leftArm[1][2] -= interval;

	//left hand
	//leftArm[2][0] += interval;
	leftArm[2][1] += interval;
	leftArm[2][2] -= interval;

}
void GumdropSkeleton::MoveRightLegForward(GLint milliseconds)
{
		GLfloat interval;

	//if no time given, then just show the keyframe
	interval = (milliseconds == 0? 100.0f*PI/180.0f :  100.0f*PI/180.0f/(GLfloat)milliseconds);

	//Rotate entire model about the y-axis with pivot pelvis right leg joint
	//pelvis[0][0] += interval;
	//pelvis[0][1] += interval;
	pelvis[2][2] += interval;//pelvis[0][2] + interval;
	pelvis[1][2] += interval;//pelvis[0][2] + interval;


	//Rotate all body parts the same way

	//Right leg
	//Load Pelvis joint
	//rightLeg[0][0] += interval;
	//rightLeg[0][1] += interval;
	rightLeg[0][2] += interval;// pelvis[0][2] + interval;

	//Load Foot
	//rightLeg[1][0] += interval;
	//rightLeg[1][1] += interval;
	rightLeg[1][2] += interval;//pelvis[0][2] + interval;

	//Spine
	//neck starting position
	//spine[0][0] += interval;
	//spine[0][1] += interval;
	spine[0][0] += interval;//pelvis[0][2] + interval;

	// shoulder joint starting position
	//spine[1][0] += interval;
	//spine[1][1] += interval;
	spine[1][0] += interval;//pelvis[0][2] + interval;

	// Abdomin ending position
	//spine[2][0] += interval;
	//spine[2][1] += interval;
	spine[2][0] += interval;//pelvis[0][2] + interval;
	
	//shoulders
	//Left Arm joint
	//shoulders[0][0] += interval;
	//shoulders[0][1] += interval;
	shoulders[0][2] += interval;//pelvis[0][2] + interval;

	//Spinal Joint
	//shoulders[1][0] += interval;
	//shoulders[1][1] += interval;
	shoulders[1][2] += interval;//pelvis[0][2] + interval;

	//Right Arm Joint
	//shoulders[2][0] += interval;
	//shoulders[2][1] += interval;
	shoulders[2][2] += interval;//pelvis[0][2] + interval;

	//rightArm
	//Shoulder joint
	//rightArm[0][0] += interval;
	//rightArm[0][1] += interval;
	rightArm[0][0] += interval;//pelvis[0][2] + interval;

	//elbow joint
	//rightArm[1][0] += interval;
	//rightArm[1][1] += interval;
	rightArm[1][0] += interval;//pelvis[0][2] + interval;

	//right hand
	//rightArm[2][0] += interval;
	//rightArm[2][1] += interval;
	rightArm[2][0] += interval;//pelvis[0][2] + interval;

	//leftArm
	//Shoulder joint
	//leftArm[0][0] += interval;
	//leftArm[0][1] += interval;
	leftArm[0][0] += interval;//pelvis[0][2] + interval;

	//elbow joint
	//leftArm[1][0] += interval;
	//leftArm[1][1] += interval;
	leftArm[1][0] += interval;//pelvis[0][2] +  interval;

	//left hand
	//leftArm[2][0] += interval;
	//leftArm[2][1] += interval;
	leftArm[2][0] += interval;//pelvis[0][2] + interval;

}
void GumdropSkeleton::DropRightLeg(GLint milliseconds)
{
	GLfloat interval;

	//Point of rotation is the right leg joint on the pelvis
	//Rotate the model clockwise about the x-axis on point
	//if no time given, then just show the keyframe
	interval = (milliseconds == 0? -100.0f*PI/180.0f : -100.0f*PI/180.0f/(GLfloat)milliseconds);

	pelvis[1][0] += interval;
	pelvis[1][1] += interval;
	pelvis[2][0] += interval;
	pelvis[2][1] += interval;


	//Right leg
	//Load Pelvis joint
	rightLeg[0][0] += interval;
	rightLeg[0][1] += interval;
	//rightLeg[0][2] += interval;

	//Load Foot
	rightLeg[1][0] += interval;
	rightLeg[1][1] += interval;
	//rightLeg[1][2] += interval;

	//Spine
	//neck starting position
	//spine[0][0] += interval;
	spine[0][1] += interval;
	spine[0][2] -= interval;

	// shoulder joint starting position
	//spine[1][0] += interval;
	spine[1][1] += interval;
	spine[1][2] -= interval;

	// Abdomin ending position
	//spine[2][0] += interval;
	spine[2][1] += interval;
	spine[2][2] -= interval;
	
	//shoulders
	//Left Arm joint
	shoulders[0][0] += interval;
	shoulders[0][1] += interval;
	//shoulders[0][2] = 0.0f;

	//Spinal Joint
	shoulders[1][0] += interval;
	shoulders[1][1] += interval;
	//shoulders[1][2] = 0.0f;

	//Right Arm Joint
	shoulders[2][0] += interval;
	shoulders[2][1] += interval;

	//rightArm
	//Shoulder joint
	//rightArm[0][0] += interval;
	rightArm[0][1] += interval;
	rightArm[0][2] -= interval;

	//elbow joint
	//rightArm[1][0] += interval;
	rightArm[1][1] += interval;
	rightArm[1][2] -= interval;

	//right hand
	//rightArm[2][0] += interval;
	rightArm[2][1] += interval;
	rightArm[2][2] -= interval;

	//leftArm
	//Shoulder joint
	//leftArm[0][0] += interval;
	leftArm[0][1] += interval;
	leftArm[0][2] -= interval;

	//elbow joint
	//leftArm[1][0] += interval;
	leftArm[1][1] += interval;
	leftArm[1][2] -= interval;

	//left hand
	//leftArm[2][0] += interval;
	leftArm[2][1] += interval;
	leftArm[2][2] -= interval;
}


void GumdropSkeleton::PlayWalkingAnimation()
{
	currentAnimation = WALKING;
	static bool isRightFootMoving = true;
	static GLint interval = 0;
	const GLint INTERVAL = 20;


	if(isRightFootMoving)
	{
		//lift leg
		if (interval <= INTERVAL/2)
		{
			LiftRightLeg(INTERVAL);
			MoveRightLegForward(2*INTERVAL);
		}
		else
		{
			MoveRightLegForward(2*INTERVAL);
			DropRightLeg(INTERVAL);
		}


	}
	else 
	{
		//lift leg
		if (interval <= INTERVAL/2)
		{
			LiftLeftLeg(INTERVAL);
			MoveLeftLegForward(2*INTERVAL);
		}
		else
		{
			MoveLeftLegForward(2*INTERVAL);
			DropLeftLeg(INTERVAL);
		}

	}



	if (interval ==	INTERVAL)
	{
		isRightFootMoving = (isRightFootMoving == true ? false : true);
		interval = 0;
	}
	interval ++;	
	
}

void GumdropSkeleton::SetConeWaterLevel(GLfloat l)
{
	coneWaterLevel = l;
}

void GumdropSkeleton::SetConeTopRadius(GLfloat t)
{
	topRadius = t;
}

GLfloat GumdropSkeleton::GetRootBoneX()
{
	return pelvis[1][0];
}

GLfloat GumdropSkeleton::GetRootBoneY()
{
	return pelvis[1][1];
}

GLfloat GumdropSkeleton::GetRootBoneZ()
{
	return pelvis[1][2];
}